﻿@{
    ViewBag.Title = "区域管理";
    Layout = "~/Views/Shared/InfoMaste.cshtml";
}
<script language="javascript" type="text/javascript">
    function doSearch() {
        $('#dg').treegrid('load', {

        });
    }

    function getAreaInfoModel(AreaId, postType) {
        $.post("/BasicManage/GetAreaInfoModel", { AreaId: AreaId }, function (json) {
            //1 新增  2编辑
            if (postType == 1) {
                data = {
                    "ParentId": json.Data.AreaId,
                    "ParentName": json.Data.AreaName,
                };
                $('#fm').form('load', data);
            } else {
                data = {
                    "AreaId": json.Data.AreaId,
                    "AreaName": json.Data.AreaName,
                    "ParentId": json.Data.ParentId,
                    "ParentName": json.Data.ParentId == 0 ? "顶级" : json.Data.ParentName,
                };
                $('#fm').form('load', data);
            }
        });

    }

    function addAreaInfo(AreaId) {;
        if (AreaId != undefined) {
            getAreaInfoModel(AreaId, 1)
        }
        else {
            data = {
                "ParentId": 0,
                "ParentName": "顶级",
            };
            $('#fm').form('load', data);
        }
        $('#dlg').dialog('open');
        url = '/BasicManage/AddAreaInfo';
    }

    function editAreaInfo(AreaId) {
        if (AreaId == undefined) {
            return;
        }
        getAreaInfoModel(AreaId, 2);
        $('#dlg').dialog('open').dialog('setTitle', '编辑');
        url = "/BasicManage/EditAreaInfo";

    }

    function delAreaInfo() {
        var row = $('#dg').treegrid('getSelected');
        if (!row) {
            Helper.Show('请选择需要删除的信息?');
            return false;
        }
        $.messager.confirm('提示信息', '删除的数据无法恢复,您确认要删除吗?', function (r) {
            if (!r) { return false; }
            $.post("/BasicManage/DelAreaInfo", { id: row.AreaId }, function (json) {
                Helper.Show(json.Msg);
                if (json.Code == 1) {
                    doSearch();
                }
            });
        });
    }

    function areaInfoSave() {
        $('#fm').form('submit', {
            url: url,
            onSubmit: function () {
                return $(this).form('validate');
            },
            success: function (json) {
                var json = eval('(' + json + ')');
                Helper.Show(json.Msg);
                if (json.Code == 1) {
                    $('#fm').form('clear');
                    $('#dlg').dialog('close');
                    $('#dg').treegrid('reload');
                }
            }
        });
    }


    function formatterAreaId(value, rowData) {
        return "<a href='javascript:' style='color:black;' onclick='addAreaInfo(" + value + ")' > 添加</a>\
                <a href='javascript:' style='color:black;' onclick='editAreaInfo(" + value + ")'> 编辑</a>";
    }
</script>
<table id="dg" class="easyui-treegrid" style="$(this).width() * 0.2; height: 400px;"
       url="/BasicManage/GetAreaInfoList" toolbar="#tb" title="区域信息" rownumbers="true"
       fitcolumns="true" singleselect="true" idField="AreaId" treeField="AreaName">
    <thead>
        <tr>
            <th field="AreaId" align="left" width="150" formatter="formatterAreaId">
                操作
            </th>
            <th field="AreaName" align="left" width="150">
                区域名称
            </th>

        </tr>
    </thead>
</table>
<div id="tb" style="padding: 3px; height: auto;">
    <a href="javascript:" class="easyui-linkbutton" iconcls="icon-add" plain="true" onclick="addAreaInfo()">新建</a>
    <a href="javascript:" class="easyui-linkbutton" iconcls="icon-no" plain="true" onclick="delAreaInfo()">删除</a>
    <a href="javascript:" class="easyui-linkbutton" plain="true" iconcls="icon-search" onclick="doSearch()">查询</a>
</div>
<div id="dlg" class="easyui-dialog" title="新增" data-options="iconCls:'icon-save'"
     closed="true" style="width: 450px; height: 300px; padding: 10px 20px" buttons="#dlg-buttons" modal="true">
    <form id="fm" method="post" novalidate>
        <input name="AreaId" type="hidden" />
        <div class="fitem">
            <label>
                所属父级:
            </label>
            <input name="ParentName" readonly="readonly" class="easyui-textbox" style="width: 173px; height: 30px;" />
            <input name="ParentId" type="hidden" />
        </div>
        <div class="fitem">
            <label>
                区域名称:
            </label>
            <input name="AreaName" class="easyui-validatebox textbox" data-options="required:true,validType:'length[1,20]'" style="width: 173px; height: 30px;" autocomplete="off" />
        </div>
    </form>
</div>
<div id="dlg-buttons">
    <a href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-ok" onclick="areaInfoSave()">保存</a>
    <a href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-cancel" onclick="javascript:$('#dlg').dialog('close')">取消</a>
</div>

